home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
mail
/
pop.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
7KB
|
171 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
from mail.smtp import SMTPEmailAccount
from common import pref
from util import dictadd, threaded, ResetTimer, get
from logging import getLogger
log = getLogger('popmail')
info = log.info
from mail.emailobj import DecodedEmail
from mail.emailobj import Email
import email
import cPickle
from zlib import decompress, compress
from hashlib import sha1
from util import CommandQueue, cmdqueue, callback_cmdqueue
class PopMail(SMTPEmailAccount):
protocol = 'pop'
default_timeout = 20
def __init__(self, **options):
pprint = pprint
import pprint
pprint(options)
d = self.default
self.popserver = options.pop('popserver', '')
self.require_ssl = options.pop('require_ssl', d('require_ssl'))
self.popport = options.pop('popport', d('popport'))
self.uidlworks = None
self.topworks = True
self.cmdq = CommandQueue(start_hooks = [
self._connect], end_hooks = [
self._quit])
self.timeouttimer = ResetTimer(pref('pop.timeout', self.default_timeout), self.timeout_check)
SMTPEmailAccount.__init__(self, **options)
can_has_preview = True
def timeout_check(self):
log.info('Checking server connection for %r', self)
if self.state in (self.Statuses.OFFLINE, self.Statuses.ONLINE):
log.info('%s is not currently checking', self)
return True
if get(self, 'conn', False):
try:
self.conn.noop()
self.on_error()
log.error("%s's server connection has failed", self)
return False
else:
log.error('%s has no conn attribute', self)
self.on_error()
return False
def update(self):
SMTPEmailAccount.update(self)
log.info('starting timeout timer')
self.timeouttimer.start()
self.real_update(success = self.finish_update)
def finish_update(self, updates):
import time as time
if self.state == self.Statuses.OFFLINE:
log.error('finish_update exiting early, state is %s', self.state)
return None
(updated_emails, updated_count) = updates
log.info('%s got %d new messages %s', self, updated_count, time.ctime(time.time()))
self._received_emails(updated_emails[:25], updated_count)
self.error_count = 0
log.info('stopping timeout timer')
self.timeouttimer.stop()
def real_update(self):
if self.state == self.Statuses.OFFLINE:
return None
conn = self.conn
(num_emails, box_size) = conn.stat()
num_emails = int(num_emails)
emails = []
def retr(mid):
if self.topworks:
try:
return conn.top(mid, 100)
self.topworks = False
return conn.retr(mid)
uidl = conn.uidl()
return (emails, num_emails)
real_update = callback_cmdqueue()(real_update)
def _connect(self):
if self.require_ssl:
pop = POP3_SSL
import poplib
else:
pop = POP3
import poplib
try:
conn = pop(self.popserver, self.popport)
except Exception:
e = None
log.error('There was an error connecting: %s', e)
self.on_error()
raise
self.conn = conn
log.info(conn.user(self.name))
try:
password = self._decryptedpw().encode('utf-8')
log.info(conn.pass_(password))
except Exception:
e = None
log.error('Bad password: %s', e)
self.error_txt = e.message
self.set_offline(self.Reasons.BAD_PASSWORD)
self.timer.stop()
raise
return conn
def _quit(self):
try:
self.conn.quit()
except Exception:
e = None
log.error('Error when disconnecting: %s', str(e))
if self.state != self.Statuses.ONLINE:
self.set_offline(self.Reasons.CONN_FAIL)
except:
self.state != self.Statuses.ONLINE
def delete(self, msg):
SMTPEmailAccount.delete(self, msg)
conn = self.conn
delete = cmdqueue()(delete)
def _get_options(self):
opts = SMTPEmailAccount._get_options(self)
opts.update((dict,)((lambda .0: for a in .0:
(a, getattr(self, a)))('popserver popport require_ssl'.split())))
return opts
if __name__ == '__main__':
from gui.toolbox import setuplogging
setuplogging()
PopMail('kevinwatters', 'linc4', popserver = 'pop.hotpop.com', popport = 110, require_ssl = False).update()